'''
Created on Mar 21, 2012
TestCase ID: Ecom_5002
Description: Kiem thu chuc nang tim kiem bai hoc
@author: Vu Dao
'''
import unittest


import time
import HTMLTestRunner
from Functions.globalFunc import preCondition, readData, endCondition
from Functions.loginPageFunc import login
from Functions.administratorFunc import clickOnBtnLessons
from Functions.lessonsFunc import searchLesson, isLessonSearch

username = readData("username")
password = readData("password")
lessonName = readData("lessonName")
class Ecom_5002(unittest.TestCase):

    def setUp(self):
        print "Buoc 1: Mo website"
        preCondition(self)

    def test_Ecom_5002(self):
        print "Buoc 2: Dang nhap vao website"
        login(self,username,password)
        
        print "Buoc 3: Click vao lessons button"
        clickOnBtnLessons(self)

        print "Buoc 4: Nhap ten bai hoc can tim kiem vao o tim kiem va nhan enter"
        searchLesson(self,lessonName)
        
        print "Buoc 5: Kiem tra bai hoc duoc tim thay tren website" 
        self.assertTrue(isLessonSearch(self,lessonName), "Failed: Bai hoc khong duoc tim thay tren website")
        print "Passed: Bai hoc duoc tim thay tren website"
        
    def tearDown(self):
        print "Buoc 6: Dong website"
        endCondition(self)


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5002)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner.HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang tim kiem bai hoc'
                    )
    runner.run(suite)